// ** Copyright (c) 2011* Freiburg, Germany * All rights reserved.
// ** File name：Expression.cpp
// ** Current version：1.0 * Author：Yongkang Zhong * Finish time：22.05.2011
// ** Replace version：1.0 * Original author: Yongkang Zhong * Finish time：22.05.2011

#include "Term.h"

// The function expr() , which returns the value that results 
// from evaluating the whole expression in the input buffer.
double expr(char *str)
{
    int index = 0;
    double value = 0.0;
    
    value = term(str, index);
    
    while (true)
    {
        switch(str[index])
        {
            case '+':
                value += term(str, ++index);
                break;
            case '-':
                value -= term(str, ++index);
                break;
            default:
                return value;
        }
    }
    
    return value;   
}
